package com.toobigtofail
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Backdrop;
	import net.flashpunk.graphics.Canvas;
	import net.flashpunk.graphics.Graphiclist;
	import net.flashpunk.graphics.Image;

	public class Background extends Entity
	{
		[Embed(source="/assets/gfx/wall.png")] private static const BACKGROUND_PNG:Class;
		
		private const SCROLL_RATE:Number = 1;
		
		private var _offsetX:Number = 0;
		private var _bCanvas:Canvas = new Canvas(800,800);
		private var _brickImg:Backdrop = new Backdrop(BACKGROUND_PNG);
		private var _gfxList:Graphiclist = new Graphiclist();
		
		public var speed:Number = BaseEnemy.FAST_SPEED;
		
		public var deceleration:Number = 0;
		
		public function Background()
		{			
			this.x = 0;
			this.y = 0;
			_bCanvas.drawGraphic(_offsetX,0, _brickImg);
			
			_gfxList.add(_bCanvas);
			graphic = _gfxList;
		}
		
		override public function update():void
		{
			speed -= deceleration * FP.elapsed;
			if (speed < 0) {
				speed = 0;
				deceleration = 0;
			}
			_offsetX -= FP.elapsed*SCROLL_RATE * speed;
			_bCanvas.drawGraphic(_offsetX, 0, _brickImg);
			
			super.update();
		}
	}
}